package com.codewsq;

import org.junit.Test;

import java.net.MalformedURLException;
import java.net.URL;

public class URLTest1 {

    @Test
    public void test() {
        try {
            // http://localhost:8080/examples/beauty.jpg?username=Tom
            // https://tse3-mm.cn.bing.net/th/id/OIP-C.UJn6UIedh0fIZk5V4f_5zgHaE8?pid=ImgDet&rs=1
            URL url = new URL("https://tse3-mm.cn.bing.net/th/id/OIP-C.UJn6UIedh0fIZk5V4f_5zgHaE8?pid=ImgDet&rs=1");

//            public String getProtocol(  )     获取该URL的协议名
            System.out.println(url.getProtocol());
//            public String getHost(  )           获取该URL的主机名
            System.out.println(url.getHost());
//            public String getPort(  )            获取该URL的端口号
            System.out.println(url.getPort());
//            public String getPath(  )           获取该URL的文件路径
            System.out.println(url.getPath());
//            public String getFile(  )             获取该URL的文件名
            System.out.println(url.getFile());
//            public String getQuery(   )        获取该URL的查询名
            System.out.println(url.getQuery());
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }
}
